﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CommonTools;
using CommonTools.Controls;
using shop.Bll;
using shop.Model;

namespace shop.daifa
{
    public class ShopLoginBllUI: ShopLoginBll
    {
        private ControlBuilder _builder;

        public override ControlBuilder GetUIBuilder()
        {
            _builder= base.GetUIBuilder()
                .SetFlowBreak()
                .AddButton("修改密码", ChangePwd, false)
                ;
            return _builder;
        }

        private async Task<PageButtonResult> ChangePwd()
        {
            var data = base.GetRowData();
            if (data.Data == null || data.Data.Id <= 0)
            {
                return new PageButtonResult(ResultCode.Error, "请先选择一个项目");
            }


            var bl = InputBox.GetPassword("请输入密码", out var pwd);
            if (bl )
            {
                var res = await base.EditCell(nameof(ShopLogin.Password), pwd, data.Data);
                if (res.IsOk)
                {
                    return new PageButtonResult(true, "修改成功!");
                }
                else
                {
                    return new PageButtonResult(false, res.Message);
                }
            }

            return new PageButtonResult(ResultCode.Warning, "", false);
        }

    }
}
